package com.sgcc.ln.pmos.common.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.common.bean.StockBean;
import java.math.BigDecimal;
import java.util.List;

public class StockAdapter extends BaseQuickAdapter<StockBean, BaseViewHolder> {

    public StockAdapter(List<StockBean> list) {
        super(R.layout.item_stock, list);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, StockBean s) {
        baseViewHolder.setText(R.id.time_txt, getgData(s.getTime()));
        baseViewHolder.setText(R.id.power_txt, convertDoubleToString(s.getPower()+"")+"MWh");
    }

    private String getgData(String s){
        String time;
        s.substring(0,4);
        time=  s.substring(0,4)+"-"+s.substring(4,6);
        return time;
    }
    private String convertDoubleToString(String num) {
        BigDecimal bd = new BigDecimal(num);
        return bd.setScale(3, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString();

    }
}
